package com.howcan.widget;


import com.howcan.v1.R;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Parcelable;
import android.util.*;
import android.widget.*;

//Referenced classes of package com.dianping.widget:
//			DPEditText

public class HcBasicItem extends LinearLayout
{

	public static final int TEXT_TYPE_BLACK_COLOR = 8;
	public static final int TEXT_TYPE_BOLD = 16;
	public static final int TEXT_TYPE_GRAY_COLOR = 4;
	public static final int TEXT_TYPE_SMALL = 1;
	public static final int TEXT_TYPE_YELLOW_COLOR = 2;
	private int checked;
	private boolean clickable;
	private String count;
	private int count_textType;
	private String input;
	private String input_hint;
	private int input_maxLength;
	private int input_textType;
	private int input_type;
	private ImageView itemArrow;
	private CheckBox itemCheckBox;
	private TextView itemCount;
	private HcEditText itemInput;
	private TextView itemSubtitle;
	private TextView itemTitle;
	private LinearLayout itemTitleLay;
	private Context mContext;
	private String subTitle;
	private int subTitle_textType;
	private String title;
	private int title_textType;

	
	public HcBasicItem(Context context)
	{
		this(context, null);
		mContext = context;
	}

	
	public HcBasicItem(Context context, AttributeSet attributeset)
	{
		super(context, attributeset);
		mContext = context;
		TypedArray typedarray = context.obtainStyledAttributes(attributeset, R.styleable.HcBasicItem);
		title = typedarray.getString(R.styleable.HcBasicItem_title);
		subTitle = typedarray.getString(R.styleable.HcBasicItem_subTitle);
		input = typedarray.getString(R.styleable.HcBasicItem_input);
		input_hint = typedarray.getString(R.styleable.HcBasicItem_input_hint);
		input_type = typedarray.getInt(R.styleable.HcBasicItem_input_type, 1);
		input_maxLength = typedarray.getInt(R.styleable.HcBasicItem_input_maxLength, 0);
		count = typedarray.getString(R.styleable.HcBasicItem_count);
		checked = typedarray.getInt(R.styleable.HcBasicItem_checked, 0);
		title_textType = typedarray.getInt(R.styleable.HcBasicItem_title_textType, 0);
		subTitle_textType = typedarray.getInt(R.styleable.HcBasicItem_subTitle_textType, 0);
		count_textType = typedarray.getInt(R.styleable.HcBasicItem_count_textType, 0);
		input_textType = typedarray.getInt(R.styleable.HcBasicItem_input_textType, 0);
		clickable = typedarray.getBoolean(R.styleable.HcBasicItem_clickable, false);
		typedarray.recycle();
		setupView(context);
	}

	private int dip2px(float f)
	{
		return (int)(0.5F + f * mContext.getResources().getDisplayMetrics().density);
	}

	
	private void setTextType(TextView textview, int i)
	{
		Resources resources = mContext.getResources();
		if (i != 0)
		{
			if ((i & 1) == 1)
				textview.setTextAppearance(mContext, R.style.content_page_small_text);
			if ((i & 2) == 2)
				textview.setTextColor(resources.getColorStateList(R.color.text_yellow_color_selector));
			if ((i & 4) == 4)
				textview.setTextColor(resources.getColorStateList(R.color.text_gray_color_selector));
			if ((i & 8) == 8)
				textview.setTextColor(resources.getColorStateList(R.color.text_color_selector));
			if ((i & 0x10) == 16)
				textview.getPaint().setFakeBoldText(true);
			else
				textview.getPaint().setFakeBoldText(false);
		}
	}

	
	private void setupView(Context context)
	{
		Resources resources = context.getResources();
		android.content.res.ColorStateList colorstatelist = resources.getColorStateList(R.color.text_color_selector);
		itemTitleLay = new LinearLayout(context);
		itemTitleLay.setDuplicateParentStateEnabled(true);
		itemTitle = new TextView(context);
		itemTitle.setId(R.styleable.HcBasicItem_title);
		itemTitle.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2));
		itemTitle.setText(title);
		itemTitle.setDuplicateParentStateEnabled(true);
		itemTitle.setTextAppearance(context, R.color.text_color_default);
		itemTitle.setTextAppearance(context, R.style.content_page_small_text);
		itemTitle.setTextColor(colorstatelist);
		itemTitle.setSingleLine(true);
		itemTitle.setEllipsize(android.text.TextUtils.TruncateAt.END);
		itemTitle.setPadding(0, 0, dip2px(10F), 0);
		itemTitle.setTypeface(Typeface.create(Typeface.DEFAULT, 1));
		setTextType(itemTitle, title_textType);
		itemTitleLay.addView(itemTitle);
		itemSubtitle = new TextView(context);
		itemSubtitle.setId(R.styleable.HcBasicItem_subTitle);
		itemSubtitle.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2));
		itemSubtitle.setText(subTitle);
		itemSubtitle.setDuplicateParentStateEnabled(true);
		itemSubtitle.setTextAppearance(context, R.color.base_start_color_default);
		itemSubtitle.setTextColor(colorstatelist);
		itemSubtitle.setSingleLine(true);
		itemSubtitle.setEllipsize(android.text.TextUtils.TruncateAt.END);
		setTextType(itemSubtitle, subTitle_textType);
		itemTitleLay.addView(itemSubtitle);
		addView(itemTitleLay);
		itemInput = new HcEditText(context);
		itemInput.setId(R.styleable.HcBasicItem_input);
		android.widget.LinearLayout.LayoutParams layoutparams = new android.widget.LinearLayout.LayoutParams(-1, -2);
		itemInput.setLayoutParams(layoutparams);
		itemInput.setGravity(16);
		itemInput.setText(input);
		itemInput.setDuplicateParentStateEnabled(true);
		itemInput.setTextAppearance(context, R.color.base_start_color_default);
		itemInput.setTextAppearance(context, R.style.content_page_small_text);
		itemInput.setTextColor(colorstatelist);
		itemInput.setSingleLine(true);
		itemInput.setEllipsize(android.text.TextUtils.TruncateAt.END);
		itemInput.setHint(input_hint);
		itemInput.setInputType(input_type);
		itemInput.setMaxLength(input_maxLength);
		itemInput.setBackgroundDrawable(null);
		itemInput.setPadding(0, 0, 0, 0);
		setTextType(itemInput, input_textType);
		addView(itemInput);
		itemCount = new TextView(context);
		itemCount.setId(R.styleable.HcBasicItem_count);
		itemCount.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2));
		itemCount.setText(count);
		itemCount.setDuplicateParentStateEnabled(true);
		itemCount.setTextAppearance(context, R.color.text_color_default);
		itemCount.setTextColor(resources.getColorStateList(R.color.text_gray_color_selector));
		setTextType(itemCount, count_textType);
		addView(itemCount);
		itemCheckBox = new CheckBox(context);
		itemCheckBox.setId(R.styleable.HcBasicItem_checked);
		itemCheckBox.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dip2px(26F), dip2px(25F)));
		CheckBox checkbox = itemCheckBox;
		boolean flag;
		if (checked == 1)
			flag = true;
		else
			flag = false;
		checkbox.setChecked(flag);
		itemCheckBox.setPadding(0, 0, 0, 0);
		addView(itemCheckBox);
		itemArrow = new ImageView(context);
//		itemArrow.setId(R.styleable.hc);
		itemArrow.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2));
		itemArrow.setPadding(dip2px(10F), 0, 0, 0);
		itemArrow.setDuplicateParentStateEnabled(true);
		itemArrow.setImageResource(R.drawable.arrow);
		addView(itemArrow);
		build();
		setGravity(16);
//		setGravity(Gravity.BOTTOM);
		setMinimumHeight(dip2px(45F));
	}

	public void build()
	{
		byte byte0 = 8;
		TextView textview = itemTitle;
		byte byte1;
		TextView textview1;
		byte byte2;
		HcEditText dpedittext;
		int i;
		TextView textview2;
		int j;
		CheckBox checkbox;
		byte byte3;
		ImageView imageview;
		if (title == null)
			byte1 = byte0;
		else
			byte1 = 0;
		textview.setVisibility(byte1);
		textview1 = itemSubtitle;
		if (subTitle == null)
			byte2 = byte0;
		else
			byte2 = 0;
		textview1.setVisibility(byte2);
		dpedittext = itemInput;
		if (input_hint != null || input != null)
			i = 0;
		else
			i = byte0;
		dpedittext.setVisibility(i);
		textview2 = itemCount;
		if (count != null)
			j = 0;
		else
			j = byte0;
		textview2.setVisibility(j);
		checkbox = itemCheckBox;
		if (checked == 0)
			byte3 = byte0;
		else
			byte3 = 0;
		checkbox.setVisibility(byte3);
		imageview = itemArrow;
		if (isClickable())
			byte0 = 0;
		imageview.setVisibility(byte0);
		if (input_hint != null || input != null)
			itemTitleLay.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2, 0F));
		else
			itemTitleLay.setLayoutParams(new android.widget.LinearLayout.LayoutParams(0, -2, 1F));
		if (input_hint != null || subTitle != null)
			title_textType = 4 | title_textType;
		setTextType(itemTitle, title_textType);
		setClickable(clickable);
	}

	@Override
	protected void dispatchRestoreInstanceState(SparseArray sparsearray)
	{
		int i;
		HcEditText dpedittext;
		i = itemInput.getId();
		dpedittext = (HcEditText)findViewById(i);
		if (dpedittext != null) {
			Parcelable parcelable = (Parcelable)sparsearray.get(i);
			if (parcelable != null) dpedittext.onRestoreInstanceState(parcelable);
			int j = itemCheckBox.getId();
			CheckBox checkbox = (CheckBox)findViewById(j);
			Parcelable parcelable1 = (Parcelable)sparsearray.get(j);
			if (parcelable1 != null) checkbox.onRestoreInstanceState(parcelable1);
		} else {
		 	super.dispatchRestoreInstanceState(sparsearray);
		}
 		return;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void dispatchSaveInstanceState(SparseArray sparsearray)
	{
		int i;
		HcEditText dpedittext;
		i = itemInput.getId();
		dpedittext = (HcEditText)findViewById(i);
		if (dpedittext != null) { 
			Parcelable parcelable = dpedittext.onSaveInstanceState();
			if (parcelable != null)
				sparsearray.put(i, parcelable);
			int j = itemCheckBox.getId();
			Parcelable parcelable1 = ((CheckBox)findViewById(j)).onSaveInstanceState();
			if (parcelable1 != null) sparsearray.put(j, parcelable1);
		} else {
			super.dispatchSaveInstanceState(sparsearray);
		}
		return;
	}

	
	
	/*
	protected void dispatchRestoreInstanceState(SparseArray sparsearray)
	{
		int i;
		DPEditText dpedittext;
		i = 0x7f09001b - getId();
		dpedittext = (DPEditText)findViewById(0x7f09001b);
		if (dpedittext != null) goto _L2; else goto _L1
_L1:
		super.dispatchRestoreInstanceState(sparsearray);
_L4:
		return;
_L2:
		Parcelable parcelable = (Parcelable)sparsearray.get(i);
		if (parcelable != null)
			dpedittext.onRestoreInstanceState(parcelable);
		int j = 0x7f09001d ^ getId();
		CheckBox checkbox = (CheckBox)findViewById(0x7f09001d);
		Parcelable parcelable1 = (Parcelable)sparsearray.get(j);
		if (parcelable1 != null)
			checkbox.onRestoreInstanceState(parcelable1);
		if (true) goto _L4; else goto _L3
_L3:
	}

	protected void dispatchSaveInstanceState(SparseArray sparsearray)
	{
		int i;
		DPEditText dpedittext;
		i = 0x7f09001b - getId();
		dpedittext = (DPEditText)findViewById(0x7f09001b);
		if (dpedittext != null) goto _L2; else goto _L1
_L1:
		super.dispatchSaveInstanceState(sparsearray);
_L4:
		return;
_L2:
		Parcelable parcelable = dpedittext.onSaveInstanceState();
		if (parcelable != null)
			sparsearray.put(i, parcelable);
		int j = 0x7f09001d ^ getId();
		Parcelable parcelable1 = ((CheckBox)findViewById(0x7f09001d)).onSaveInstanceState();
		if (parcelable1 != null)
			sparsearray.put(j, parcelable1);
		if (true) goto _L4; else goto _L3
_L3:
	}

*/
	
	public String getCount()
	{
		return count;
	}

	public int getCountTextType()
	{
		return count_textType;
	}

	public String getInputHint()
	{
		return input_hint;
	}

	public int getInputMaxLength()
	{
		return input_maxLength;
	}

	public String getInputText()
	{
		return input;
	}

	public int getInputTextType()
	{
		return input_textType;
	}

	public int getInputType()
	{
		return input_type;
	}

	public String getSubTitle()
	{
		return subTitle;
	}

	public int getSubTitleTextType()
	{
		return subTitle_textType;
	}

	public String getTitle()
	{
		return title;
	}

	public int getTitleTextType()
	{
		return title_textType;
	}

	public boolean isClickable()
	{
		return clickable;
	}

	public void setClickable(boolean flag)
	{
		super.setClickable(flag);
		clickable = flag;
	}

	public void setCount(String s)
	{
		count = s;
		itemCount.setText(s);
	}

	public void setCountTextType(int i)
	{
		count_textType = i;
		setTextType(itemCount, i);
	}

	public void setHint(String s)
	{
		input_hint = s;
		itemInput.setHint(s);
	}

	public void setInputMaxLength(int i)
	{
		input_maxLength = i;
		itemInput.setMaxLength(i);
	}

	public void setInputText(String s)
	{
		input = s;
		itemInput.setText(s);
	}

	public void setInputTextType(int i)
	{
		input_textType = i;
		setTextType(itemInput, i);
	}

	public void setInputType(int i)
	{
		input_type = i;
		itemInput.setInputType(i);
	}

	public void setSubTitle(String s)
	{
		subTitle = s;
		itemSubtitle.setText(s);
	}

	public void setSubTitleTextType(int i)
	{
		subTitle_textType = i;
		setTextType(itemSubtitle, i);
	}

	public void setTitle(String s)
	{
		title = s;
		itemTitle.setText(s);
	}

	public void setTitleTextType(int i)
	{
		title_textType = i;
		setTextType(itemTitle, i);
	}
}
